﻿using Api.Application.Command.RoleMenu;
using Api.DTO;
using AutoMapper;
using Domain;
using ErrorCode;
using Infrastructure;
using MediatR;

namespace Api.Application.Handler.RoleMenu
{
    public class GetRoleMenuHandler : IRequestHandler<GetRoleMenuCommand, ApiResult<List<int>>>
    {
        private readonly IBase<RoleModel> roleRepo;
        private readonly IBase<RoleMenuModel> roleMenuRepo;
        private readonly IMapper mapper;

        public GetRoleMenuHandler(IBase<RoleModel> roleRepo,IBase<RoleMenuModel> roleMenuRepo,IMapper mapper)
        {
            this.roleRepo = roleRepo;
            this.roleMenuRepo = roleMenuRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<int>>> Handle(GetRoleMenuCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<int>> result=new ApiResult<List<int>>();
            var roleMenu=roleMenuRepo.GetAll().Where(x=>x.RoleId==request.RoleId).Select(x=>x.MenuId);

            result.Code = ApiEnum.OK;
            result.Data= roleMenu.ToList();
            result.Msg = "显示成功";
            return Task.FromResult(result);
        }
    }
}
